package com.yibo.db.helper;

import com.github.pagehelper.Page;
import com.yibo.support.pojo.YBFilter;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.LinkedList;
import java.util.List;

/**
 * 查询过滤条件
 *
 * @author zhanglei
 */
@Setter
@Getter
@Accessors(chain = true)
public class QueryFilter<T> {


    /**
     * 页长
     */
    private int pageSize = 10;


    /**
     * 页码
     */
    private int pageNum = 1;


    /**
     * 总数量
     */
    private long total;


    /**
     * 过滤条件
     */
    private List<YBFilter> filters = new LinkedList<>();



    /**
     * 数据集
     */
    private T data;


    public QueryFilter(){

    }



    public QueryFilter<T> initResult(T data){
        if(data instanceof Page){
            this.data = data;
            this.total = ((Page) data).getTotal();
            this.pageSize = ((Page) data).getPages();
            this.pageNum = ((Page) data).getPageNum();
        }else if(data instanceof List){
            this.data = data;
        }
        return this;
    }

}
